package com.yuchuang.base;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

@Data
@Accessors(chain = true) //可以以链的形式调用
//java让封装的实体类不返回为空的属性：@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(JsonInclude.Include.NON_NULL)
/**
 *@authoe    :cy
 *@date      :13:35 2023-04-25
 *description:  @JsonInclude(JsonInclude.Include.NON_NULL)：让封装的实体类不返回为空的属性
 * @Accessors(chain = true) //可以以链的形式调用
 *return     :
 **/
public class Result<E>{
    @ApiModelProperty(value="状态码")
    private Integer code;
    @ApiModelProperty(value="状态信息")
    private String message;
    private E data;
    public static <E> Result ok(E e){
        return new Result().setCode(Enum.Ok.getCode()).setMessage(Enum.Ok.getMessage()).setData(e);
    }
    public static <E> Result ok(String message,E e){
        return new Result().setCode(Enum.Ok.getCode()).setMessage(message).setData(e);
    }
    public static Result ok(String message){
        return new Result().setCode(Enum.Ok.getCode()).setMessage(message);
    }
    public static Result fail(String message){
        return new Result().setCode(Enum.Error.getCode()).setMessage(message);
    }
    public static Result fail(Enum errorEnum) {
        return  new Result().setCode(errorEnum.getCode()).setMessage(errorEnum.getMessage());
    }
}
